package com.itheima.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author huyoufu <https://github.com/huyoufu>
 * @TIME 2020-08-11 09:37
 * @description
 *
 * 最原始操作 使用request 转发的方式
 */


@Controller
@RequestMapping("/user01")
//类上不加RequestMapping注解 每个方法就需要注解@RequestMapping("/user/login.do") ,组装

public class demo1_request转发的方式 {

    @RequestMapping("/login.do")
    public void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("用户登录...");

        //响应信息
        request.setAttribute("info","模拟用户登录简单数据");
        request.getRequestDispatcher("/WEB-INF/pages/user/success.jsp").forward(request,response);

    }

    @RequestMapping("/register.do")
    public void register(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("用户注册...");
        request.setAttribute("info","模拟用户注册简单数据");
        request.getRequestDispatcher("/WEB-INF/pages/user/success.jsp").forward(request,response);

    }

    @RequestMapping("/logout.do")
    public void logout(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("退出登录...");
        request.setAttribute("info","模拟用户退出登录简单数据");
        request.getRequestDispatcher("/WEB-INF/pages/user/success.jsp").forward(request,response);

    }
}
